<?php
/**
 * Description: 获取正在直播课公开课
 * User: devforma
 * Date: 15/6/16
 * Time: 17:39
 */

class CurrentOpenCourse implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        global $cmsdb;

        $now = time();
        $startTime = date('Y-m-d H:i:s', $now + 10*60);
        $now = date('Y-m-d H:i:s', $now);

        $sql = "SELECT cover_pic, id FROM `data_live_course` WHERE `type_id`=1 AND `publish_status`='publish'
        AND `class_starttime`<'{$startTime}' AND `class_endtime`>'{$now}' LIMIT 1";

        $exists = $cmsdb->getRow($sql);

        if (empty($exists))
            return genOutput(1, array(
                'course' => null
            ));

        return genOutput(1, array(
            'course' => array(
                'id' => intval($exists->id),
                'cover_pic' => empty($exists->cover_pic) ? '' : getSecureUrl($exists->cover_pic)
            )
        ));
    }
}